﻿using UnityEngine;
using UnityEngine.UI;

namespace BToolkit
{
    public class FPS : MonoBehaviour
    {
        public static int fps { get; private set; }
        public Text text;
        float timer;

        void Awake()
        {
            Application.targetFrameRate = -1;
            timer = Time.time;
        }

        void Update()
        {
            if (Time.time > timer)
            {
                timer = Time.time + 0.2f;
                fps = Mathf.RoundToInt(1 / Time.deltaTime);
                if (text) text.text = string.Format("FPS: {0} / {1}", fps, Application.targetFrameRate);
            }
        }

    }
}